//
//  MenuFenleiListTableViewCell.m
//  Products_B
//
//  Created by lanou on 16/6/2.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "MenuFenleiListTableViewCell.h"
#import "MenuFirstModel.h"
@interface MenuFenleiListTableViewCell()
@property (nonatomic, assign)CGFloat width;
@property (nonatomic, strong)NSMutableArray *buttons;
@property (nonatomic, assign)NSInteger flag;
@end
@implementation MenuFenleiListTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.picImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 140)];
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20,100 , 200, 20)];
        self.descLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 120, 200, 20)];
        self.playLabel = [[UILabel alloc]initWithFrame:CGRectMake(kWidth - 20 - 100, 120, 100, 20)];
        self.playLabel.textAlignment = NSTextAlignmentRight;
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        self.descLabel.font = [UIFont systemFontOfSize:13];
        self.descLabel.textColor = [UIColor grayColor];
        self.playLabel.font = [UIFont systemFontOfSize:13];
        self.playLabel.textColor = [UIColor grayColor];
        self.bofangButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        self.bofangButton.frame = CGRectMake(kWidth/2 - 15, 60 - 15, 30, 30) ;
        [self.bofangButton setBackgroundImage:[UIImage imageNamed:@"menubobo"] forState:(UIControlStateNormal)];
        UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 150, 20, 20)];
        imageView1.image = [UIImage imageNamed:@"menufeiji"];
        self.bigView = [[UIView alloc]initWithFrame:CGRectMake(40, 140, kWidth, 30)];

        
        [self.picImageView addSubview:_bofangButton];
        [self.picImageView addSubview:_titleLabel];
        [self.picImageView addSubview:_descLabel];
        [self.picImageView addSubview:_playLabel];
        [self.contentView addSubview:_bigView];
        [self.contentView addSubview:imageView1];
        [self.contentView addSubview:_picImageView];
    }
    return self;
}
- (void)setModel:(MenuFirstModel *)model
{
    _model = model;
    
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil completed:nil];
    self.titleLabel.text = model.title;
    self.descLabel.text = model.descriptiont;
    self.playLabel.text = [NSString stringWithFormat:@"%@人做过",model.play];

    if (_flag == 0) {
    for (int i = 0; i < model.bigSpArray.count; i++) {
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
        CGRect bounds = [model.bigSpArray[i] boundingRectWithSize:CGSizeMake(1000, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
        button.titleLabel.font = [UIFont systemFontOfSize:13];
        button.tintColor = [UIColor orangeColor];
        button.layer.cornerRadius = 4;
        button.layer.masksToBounds = YES;
        button.layer.borderColor = [UIColor orangeColor].CGColor;
        button.layer.borderWidth = 1;
        button.frame = CGRectMake(10 *i + self.width, 10, bounds.size.width, 20);
        
        if ([model.bigSpArray[i] isEqualToString:model.page_title]) {
            button.backgroundColor = [UIColor orangeColor];
            button.tintColor = [UIColor whiteColor];
        }
        self.width += bounds.size.width;
        [button setTitle:model.bigSpArray[i] forState:(UIControlStateNormal)];
        [self.bigView addSubview:button];
        
        _flag = 1;
    }
   
      }
    self.width = 0;
    
}
@end
